package com.credithc.signature.manager.controller.management;

import com.credithc.baseserv.core.codes.CoreCodes;
import com.credithc.baseserv.core.message.Message;
import com.credithc.baseserv.core.message.MessageFactory;
import com.credithc.signature.common.ro.manager.ChartRo;
import com.credithc.signature.common.vo.manager.ChartVo;
import com.credithc.signature.manager.service.ChartService;
import javafx.scene.chart.Chart;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.util.Date;

@RestController
@RequestMapping("/manager/scs/v2/chart")
public class ChartController {

    @Autowired
    private MessageFactory messageFactory;

    @Autowired
    private ChartService iconService;

    @GetMapping("day")
    public Message<ChartVo> dayStatistics(ChartRo chartRo) throws ParseException {

        ChartVo chartVo = iconService.dayStatistics(chartRo.getStart(), chartRo.getStop());

        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, chartVo);
    }

    @GetMapping("hour")
    public Message<ChartVo> hourStatistics(Date date){

        ChartVo chartVo = iconService.hourStatistics(date);

        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, chartVo);
    }
    @GetMapping("/channel/hour")
    public Message<ChartVo> channelHourStatistics(Date date){

        ChartVo chartVo = iconService.channelHourStatistics(date);

        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, chartVo);
    }
    @GetMapping("/date/count")
    public Message<Integer> dateCount(String date){
        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS,iconService.dateCount(date));
    }

    @GetMapping("/date/ratio")
    public Message<String> dateRatio(String date){
        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS,iconService.dateRatio(date));
    }
    @GetMapping("/date/between/count")
    public Message<String> betweenCount(Date start,Date end){
        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS,iconService.betweenCount(start,end));
    }

    @GetMapping("/info/saas")
    public Message<Chart> chartInfo(){
        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS,iconService.chartInfo());
    }
}
